package sg.edu.nus.iss;

import java.util.*;
import org.jgap.*;

/**
 * 
 * @author Xu Guoneng
 *
 */
public class InitialPopulationGenerator {

	//TODO to be further optimised
	public static void generate(Genotype genotype, Package[] seed){
		List<IChromosome> chromosomes = genotype.getPopulation().getChromosomes();
		
		if(seed != null){
			for (int i = 0; i < chromosomes.size(); i++) {
		        IChromosome chrom = chromosomes.get(i);
		        for (int j = 0; j < chrom.size(); j++) {
		          Gene gene = (Gene) chrom.getGene(j);
		          gene.setAllele(seed[j].getId()-1);
		        }
		    }
		}
		else{	//default
		    for (int i = 0; i < chromosomes.size(); i++) {
		        IChromosome chrom = chromosomes.get(i);
		        for (int j = 0; j < chrom.size(); j++) {
		          Gene gene = (Gene) chrom.getGene(j);
		          gene.setAllele(new Integer(j));
		        }
		    }
		}
	}
}
